package com.base.controller;

import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.base.comm.CommContent;
import com.base.po.voip.Notices;
import com.base.service.LogsService;
import com.base.service.NoticesService;
import com.base.utils.IP;

/**
 * 修改帮助中心信息服务端
 * 
 * @author f
 *
 */
@Controller
@RequestMapping("/admin")
public class update_Notices {

	@Autowired
	private LogsService logsService; // log日志
	@Autowired
	private NoticesService noticesService; // 帮助中心

	// 修改帮助中心信息
	@RequestMapping(value = "/toUpdateNotices", method = RequestMethod.POST)
	public @ResponseBody int toUpdateNotices(HttpServletRequest request, Notices notices) throws Exception {
		if (request.getSession().getAttribute("adminUserId") == null) return -1; // 未登录
		logsService.insert(CommContent.TYPE_UPDATE, CommContent.LOGS_UPDATE + "改动帮助中心信息",
				(String) request.getSession().getAttribute("userNick"), true, IP.getIpAddr(request)); // 记录修改日志
		return noticesService.updateByPrimaryKeySelective(notices); // 修改
	}

	// 删除帮助中心信息
	@RequestMapping(value = "/toDeleteNotices", method = RequestMethod.POST)
	public @ResponseBody int toDeleteNotices(HttpServletRequest request, String id) throws Exception {
		if (request.getSession().getAttribute("adminUserId") == null) return -1; // 未登录
		return noticesService.deleteByPrimaryKey(id); // 删除
	}
}
